package com.kedi.usercenter.controller;

import com.kedi.usercenter.service.ChildrensetService;
import com.kedi.usercenter.utils.ResultVoUtil;
import com.kedi.usercenter.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
* @Description:    子女设置
* @Author:         ytw
* @CreateDate:     2019/8/2 17:01
* @UpdateRemark:   修改内容
* @Version:        1.0
*/
@RestController
public class ChildrensetController {
    @Autowired
    ChildrensetService service;

    /**
    * 方法实现说明   插入亲情号
    * @author      ytw
    *@param
    * @return
    * @exception
    * @date        2019/8/2 17:01
    */
    @PostMapping("/createaffectionphone/as")
    ResultVo createaffectionphone( @RequestBody List<Map<String,Object>> listMap){
        HashMap<Object, Object> map1 = new HashMap<>(10);

        for (int i = 0; i < listMap.size(); i++) {
            Map<String, Object> map = listMap.get(i);
            Iterator iterator = map.keySet().iterator();
            while (iterator.hasNext()) {
                Object string =  iterator.next();
               if(string.equals("p_user_id")&&string!=null&&!"".equals(string)){
                   Object p_user_id = map.get("p_user_id");
                   map1.put("p_user_id",p_user_id);
                   service.deleteaffectionphone(map1);
               }
                if(string.equals("phone1")&&string!=null&&!"".equals(string)){
                    Object phone1 = map.get("phone1");
                    map1.put("phone",phone1);
                }
                if(string.equals("phone2")&&string!=null&&!"".equals(string)){
                    Object phone2 = map.get("phone2");
                    map1.put("phone",phone2);
                }
                if(string.equals("phone3")&&string!=null&&!"".equals(string)){
                    Object phone3 = map.get("phone3");
                    map1.put("phone",phone3);
                }
                if(map1.containsKey("p_user_id")&&map1.containsKey("phone")){
                    Integer res = service.createaffectionphone(map1);
                }
            }

        }
        return ResultVoUtil.success();


    }

    /**
    * 方法实现说明  插入药品
    * @author      ytw
    *@param
    * @return
    * @exception
    * @date        2019/8/2 17:01
    */
    @GetMapping("/createmydrug")
    ResultVo createmydrug(@RequestParam Integer p_user_id,
                          @RequestParam String drugname,@RequestParam String startime,
                          @RequestParam String endtime,@RequestParam String size,@RequestParam Integer stage){
        HashMap<Object, Object> map = new HashMap<>(20);
        map.put("p_user_id",p_user_id);
        map.put("drug_name",drugname);
        map.put("startime",startime);
        map.put("endtime",endtime);
        map.put("size",size);
        map.put("stage",stage);
        Integer res = service.createmydrug(map);
        return ResultVoUtil.success(res);
    }
    /**
    * 方法实现说明 根据用户id查找子女设置
    * @author      ytw
    *@param
    * @return
    * @exception
    * @date        2019/8/2 17:44
    */
    @RequestMapping("/findChildrenset")
    public ResultVo findChildrenset(Integer p_user_id){
        List<Map<String, Object>> res = service.findChildrenset(p_user_id);
        return ResultVoUtil.success(res);
    }


}
